home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / XCMDs and XFCNs / CharCount XFCN 1.0.0 / CharCount.c next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  1.6 KB  |  75 lines  |  [TEXT/KAHL]

  1. /* ----------------------------------------------------------------------
  2.  
  3.     CharCount XFCN
  4.     version 1.0
  5.     4 December 1993
  6.     
  7.     Written by: Paul Celestin
  8.     
  9.     This XFCN returns the number of times a specified character
  10.     appears in the source text.
  11.     
  12.     Requires two parameters: search char, source text.
  13.     
  14.     931204 - 1.0.0 - initial release
  15.  
  16. ---------------------------------------------------------------------- */
  17.  
  18. # include    <HyperXCMD.h>
  19. # include    <SetUpA4.h>
  20.  
  21. # define    NUMBER_OF_PARAMS    2
  22.  
  23. # define    NIL                    0
  24. # define    FALSE                0
  25. # define    TRUE                1
  26.  
  27. # define    BYTEMASK            0xFF
  28. # define    CRC_CONSTANT        0x1021
  29. # define    WORDMASK            0xFFFF
  30. # define    WORDBIT                0x10000
  31.  
  32. /* ----------------------------------------------------------------------
  33. prototypes
  34. ---------------------------------------------------------------------- */
  35.  
  36. pascal void main(XCmdPtr paramPtr);
  37.  
  38. /* ----------------------------------------------------------------------
  39. main - here is where it all began...
  40. ---------------------------------------------------------------------- */
  41. pascal void main(XCmdPtr paramPtr)
  42. {
  43.     char        *p,*c;
  44.     long        count = 0;
  45.     StringPtr    myString;
  46.  
  47.      RememberA0();
  48.      SetUpA4();
  49.      
  50.     if (paramPtr->paramCount == NUMBER_OF_PARAMS)
  51.     {
  52.         MoveHHi(paramPtr->params[0]);
  53.         MoveHHi(paramPtr->params[1]);
  54.         HLock(paramPtr->params[0]);
  55.         HLock(paramPtr->params[1]);
  56.  
  57.         p = *(paramPtr->params[0]);
  58.         c = *(paramPtr->params[1]);
  59.         
  60.         while (*c)
  61.         {
  62.             if (*c++ == *p)
  63.                 ++count;
  64.         }
  65.         NumToStr(paramPtr,count,myString);
  66.  
  67.         paramPtr->returnValue = PasToZero(paramPtr,myString);
  68.         
  69.         HUnlock(paramPtr->params[0]);
  70.         HUnlock(paramPtr->params[1]);
  71.     }
  72.     
  73.     RestoreA4();
  74. }
  75.